<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="用人单位" class="row-padding-bottom">
              <el-input
                placeholder="输入企业名称或统一社会信用代码"
                clearable
                v-model="filterField.name"
                @blur="filterField.name = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="单位类型" class="row-padding-bottom">
              <el-select
                v-model="filterField.departmentType"
                placeholder="请选择"
                clearable
              >
                <el-option label="企业" value="0"></el-option>
                <el-option label="事业单位" value="5"></el-option>
                <el-option label="个体工商户" value="15"></el-option>
                <el-option label="其他" value="10"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="归属" class="row-padding-bottom">
                <el-select
                  v-model="filterField.belongs"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="本地" value="1"></el-option>
                  <el-option label="外地" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="经营地区" class="row-padding-bottom">
                <el-cascader
                  ref="manageArea"
                  v-model="bizAreaId"
                  :options="areasOptions"
                  @change="getAreaId"
                  clearable
                  filterable
                  :props="{ checkStrictly: true }"
                  placeholder="请选择"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" prop="industry">
                <el-cascader
                  ref="industry"
                  v-model="industryId"
                  :options="industryOptionsNC"
                  @change="getIndustryId"
                  :props="{ checkStrictly: true }"
                  clearable
                  filterable
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="累计员工" class="row-padding-bottom">
                <el-select
                  v-model="filterField.isEmployee"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="有员工" value="1"></el-option>
                  <el-option label="无员工" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="考勤信息" class="row-padding-bottom">
                <el-select
                  v-model="filterField.isAtt"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="有考勤" value="1"></el-option>
                  <el-option label="无考勤" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="工资账户" class="row-padding-bottom">
                <el-select
                  v-model="filterField.isAccount"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="有账户" value="1"></el-option>
                  <el-option label="无账户" value="0"></el-option>
                  <!--                            <el-option label="基本户" value="1"></el-option>-->
                  <!--                            <el-option label="一般户" value="0"></el-option>-->
                  <!--                            <el-option label="个人账户" value="2"></el-option>-->
                  <!--                            <el-option label="未填写" value="3"></el-option>-->
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="工资发放" class="row-padding-bottom">
                <el-select
                  v-model="filterField.isSalary"
                  placeholder="请选择"
                  clearable
                >
                  <el-option label="有代发记录" value="1"></el-option>
                  <el-option label="无代发记录" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchTable"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableData.length"
                :filterField="filterField"
                api="api-s/report/export_JC_NC_COMPANIES"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing" v-if="!hiddleToolBar"></div>
      <!-- 列表 -->
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          @sort-change="sortChange"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            align="center"
            prop="locatedDate"
            label="入驻日期"
            sortable="custom"
            :formatter="formatTd"
            min-width="130"
          ></el-table-column>
          <!-- <el-table-column align="center" prop="name" label="用人单位" :formatter=formatTd></el-table-column> -->
          <el-table-column label="用人单位" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.name"
                :columnName="'name'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="uscc"
            label="企业统一社会信用代码"
            :formatter="formatTd"
            min-width="190"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="departmentName"
            label="单位类型"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="enterpriseBelongs"
            label="归属"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="bizAreaName"
            label="区域"
            :formatter="formatTd"
            min-width="150"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="empTotal"
            label="累计员工数"
            sortable="custom"
            :formatter="formatTd"
            min-width="130"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="jobEmpTotal"
            label="在职员工数"
            sortable="custom"
            :formatter="formatTd"
            min-width="130"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="attTotal"
            label="累计考勤人次"
            sortable="custom"
            :formatter="formatTd"
            min-width="140"
          ></el-table-column>
          <!--                <el-table-column align="center" prop="updateTime" label="账户类型" :formatter=formatTd width="110px"></el-table-column>-->
          <el-table-column
            align="center"
            prop="salaryAccountBank,salaryAccount"
            label="工资账户"
            :formatter="formatTd"
            width="130"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.salaryAccountBank }}</p>
              <p>
                {{ scope.row.salaryAccount | deseHandler(4, 4, '*') || '--' }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="saAmountTotal"
            label="工资发放"
            :formatter="formatTd"
            width="110px"
          >
            <template slot-scope="scope">
              <p v-if="scope.row.saAmountTotal > 0">有代发记录</p>
              <p v-else>无代发记录</p>
            </template>
          </el-table-column>
          <el-table-column align="left" label="操作" width="90px" fixed="right">
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="toDetail(scope.row)"
                v-if="isShowDetail"
                >查看</el-link
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'employerRecordList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '用人单位档案',
      advanced: false,
      requestUrl: 'api-s/nc/companystats/base/monitor/companies',
      loading: true,
      isShow: false,
      tableData: [], //表格数据
      filterField: {
        departmentType: '',
        bizAreaId: '',
        industryId: '',
        isEmployee: '', //归属
        isAtt: '', //地址
        isSalary: '', //
        isAccount: '', //审核状态
        name: '', //申请企业名称/代码
      },
      pageSize: 20,
      pageNo: 1,
      bizAreaId: '',
      industryId: '',
      isShowDetail: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptionsNC']) },
  created() {
    //获取行业
    this.getIndustryNC({})
    //获取区域
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('employerRecordList:detail') >
      -1
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    ...mapActions(['getAreas', 'getIndustryNC']),
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      this.pageSize = 20
      this.pageNo = 1
      this.$refs.pagination.getTableListData()
    },
    //获取选中的区域最后一级id
    getAreaId() {
      // if(this.filterField.bizAreaId.length > 0){
      var areaId = this.bizAreaId[this.bizAreaId.length - 1]
      this.filterField.bizAreaId = areaId
      // }
    },
    getIndustryId() {
      // if(this.filterField.industryId.length > 0){
      var industryId = this.industryId[this.industryId.length - 1]
      this.filterField.industryId = industryId
      // }
    },
    toDetail(row) {
      this.$router.push({
        path: '/home/businessManagement/enterpriseArchives',
        name: 'enterpriseArchives',
        query: {
          companyId: row.id,
          name: 'employerRecordList',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/enterpriseSet/employerRecordList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped lang="less">
.tableBox {
  .tableTitle {
    width: 100%;
    height: 50px;
    line-height: 50px;
  }
}
@import '../../../static/css/filterArea.less';
</style>
